(function() {
	var $ = require(L('$')), _ = require(L('_'));

	var win = $.createWindow(L('win_notification_details'));
	win.currentNotification = null;
	win.navbar = $.ui('navbar')(true, true);
	var ui = $.layout('notifications/details');
	ui.top.add($.ui('partial').scan_and_take_photo());
	win.add([win.navbar, ui.view]);
	win.display = function(notificationID, canGoBack) {
		canGoBack = canGoBack === false ? false : true;
		win.navbar.update(canGoBack, true);
		$.opacity_show(ui.view, false);
		$.mask();
		$.webservice().getNotificationDetails(notificationID, function(e, nothingNew) {
		    var result = JSON.parse(e);
		    if (!nothingNew && result) {
                $.badgeNotification(result.UnreadNotificationNumber);
                $.ui('bottom').update_badge();
            }
			var notificationItem = result.NotificationItem;
			win.currentNotification = notificationItem;
			$.removeChildren(ui.container);
			var webView = $.createWebView('data/html/notification_details.html', {
				width : 280,
				height : Ti.UI.FILL,
				hideShadow : true
			});
			webView.onload(function() {
				webView.val('title', notificationItem.Title);
				webView.val('description', notificationItem.Description);
				if (notificationItem.AllowSharing)
					webView.css('btnShare', 'display', 'block');
			});
			ui.container.add(webView);
			$.mask(false);
			$.opacity_show(ui.view);
		});
	};
	win.share = function() {
		if (!win.currentNotification)
			return;
		$.ui('popup').share({
			fb : {
				link : win.currentNotification.ShareURL,
				name : win.currentNotification.FacebookShareContent,
				message : '',
				caption : win.currentNotification.FacebookShareCaption,
				description : win.currentNotification.FacebookShareDescription,
				picture : win.currentNotification.FacebookShareImage,
			},
			twitter : {
				message : win.currentNotification.TwitterShareContent
			},
			pinterest : null,
			email : {
				notificationID : win.currentNotification.NotificationID
			}
		}, function(type) {
			if (type == $.enum('share').Email)
				return;
			$.a(L('message_share_success'), L('message_share_success_title'));
		}).open();
	};

	module.exports = win;
})();
